package com.it.androidCommonUtils;


import java.util.concurrent.Executor;

import android.os.Handler;

public class ThreadUtils {
	
	public  static  final  Executor taskExecutor;
	
	public static Executor cacheExecutor;
	
	private static  int mThreadNum=10;
	  /**
     * 创建一个主线程中handler
     */
    public static Handler mHandler;
	static{
		
		taskExecutor=DefaultConfigurationFactory.createExecutor(mThreadNum, Thread.NORM_PRIORITY-1, DefaultConfigurationFactory.QueueProcessingType.FIFO);
		cacheExecutor=DefaultConfigurationFactory.createTaskDistributor();
		mHandler= new Handler();
		for (int i = 0; i < mThreadNum; i++) {
			taskExecutor.execute(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
//					System.out.println(Thread.currentThread().getName());
				}
			});
		}
    }
	
	
	public static void initThreadNum(int threadNum){
		mThreadNum=threadNum;
		
	}
    /**
     * 子线程执行task
     */
    public static void runInSubThread(Runnable task) {
    	taskExecutor.execute(task);
    }

  

    /**
     * UI线程执行task
     */
    public static void runInUIThread(Runnable task) {
        mHandler.post(task);
    }
    /**
     * UI线程执行task 延时
     * 
     */
    public static void runInUIThread(Runnable task,long delayms) {
        mHandler.postDelayed(task, delayms);
    }
   
    
    
    
}
